package net.love5z.web.dao;

import java.util.List;

import net.love5z.web.dao.dto.UserPacRuleDto;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.type.JdbcType;

public interface UserPacRuleMapper {

    @Select({ "select", " id, rule, user_id, create_time, modify_time",
            " from love5z_user_pacrule", "where user_id = #{userId} and hidden <> 1",
            "limit 0, 100" })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "rule", property = "rule", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP) })
    List<UserPacRuleDto> getPacRuleListByUserId(@Param("userId")
    long userId);

    @Insert({ "insert into love5z_user_pacrule (rule, user_id, create_time, modify_time)",
            "values (#{rule,jdbcType=VARCHAR}, #{userId, jdbcType=VARCHAR}, now(), now())" })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertRuleByUserId(@Param("rule")
    String rule, @Param("userId")
    long userId);

}
